package com.flightan.app.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * User: Aleks
 * Date: 26.02.12
 * Time: 17:48
 */
public class DateParser
{
    public static Date parseTime(String strDate, String format)
    {
        if (strDate==null || strDate.equals("")) return null;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try
        {
            return sdf.parse(strDate);
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        return null;
    }

    public static Date parseTime(String strDate, String format, Locale locale)
    {
        if (strDate==null || strDate.equals("")) return null;
        SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
        try
        {
            return sdf.parse(strDate);
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        return null;
    }


    
    public static String dateForConsole(Date date)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM HH:mm");
        return  sdf.format(date);
    }

    private void test()
    {
        String test = "02 августа 15:20";
        SimpleDateFormat sdf = new SimpleDateFormat("dd MMM ", new Locale("ru","RU"));
        try {
            Date myDate = sdf.parse(test);
            sdf.applyPattern("dd/MM/yyyy hh:mm");
            System.out.println(sdf.format(myDate));
            System.out.println((new SimpleDateFormat("dd MMM", new Locale("ru", "RU"))).parse(test));

        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
